<?php
declare (strict_types = 1);
/**
 * 家
 */
namespace app\common\admin;

use app\common\facade\admin\AdminAdmin;
use app\common\facade\admin\HomeAdmin;
use app\common\facade\extend\RedisExtend;
use think\facade\Request;

class BaseAdmin
{

    // 管理员访问地址
    protected function pathRole()
    {
        return Request::controller() . '/' . ucfirst(Request::action());
    }

    // 请求头登录密钥
    protected function accessLoginHeader()
    {
        return Request::header('accesslogin');
    }

    // 应用前缀
    protected function domainBindAdmin()
    {
        return env('domain_bind.admin');
    }

    // 登录信息
    protected function adminLoginInfo()
    {

        $accessLoginHeader = self::accessLoginHeader();

        if (empty($accessLoginHeader)) exception('登录信息出现异常，请重新登录', 80000);

        $infoAdmin = RedisExtend::hGetAll(self::domainBindAdmin() . $accessLoginHeader);

        if (empty($infoAdmin)):

            $paramAdmin = [
                'enable'      => 2,
                'accessLogin' => $accessLoginHeader,
            ];

            $infoAdmin = AdminAdmin::adminInfo($paramAdmin);

            if (empty($infoAdmin)) exception('登录信息已过期，请重新登录...', 80000);

            HomeAdmin::baseLogin($infoAdmin, $infoAdmin['accessLogin']);
        endif;

        return $infoAdmin;
    }




}
